<?php
class NewsInfoAction extends Action
{
    /**
    +----------------------------------------------------------
    *信息添加
    +----------------------------------------------------------
    */
    public function newsadd()
    {
        $news=M("news");
        $news->create();
        $news_result=$news->add();
        if($news_result)
        {
            $this->assign("jumpUrl","newsadd");
            $this->success("信息添加成功");
        }
        else
        {
              $classlist=M("class");
              $classlist_result=$classlist->select();
              $this->assign("classlistshow",$classlist_result);
              $this->display();
        }
    }
    /**
    +----------------------------------------------------------
    *信息列表
    +----------------------------------------------------------
    */
    public function newslist()
    {
         $newslist=M("news");
         $newslist_result=$newslist->field("news_id,news_class,news_title")->select();
         $this->assign("newslistshow",  $newslist_result);
         $this->display();
    }
    /**
    +----------------------------------------------------------
    *信息编辑
    +----------------------------------------------------------
    */
     public function newsedit()
    {
        $newsedit=M("news");
        if(isset($_GET['e_id']))
        {
            $classlist=M("class");
            $classlist_result=$classlist->select();
            $e_id=$_GET['e_id'];
            $edit_result= $newsedit->where("news_id=$e_id")->field('news_title,news_content')->find();
            $this->assign("classlistshow",$classlist_result);
            $this->assign('e_id',$e_id);
            $this->assign('edit_result',$edit_result);
            $this->display(newsedit);
        }
        //更新类别信息
        if(isset($_POST['u_e_id']))
        {
            $u_e_id=$_POST['u_e_id'];
            $newsedit->create();
            $info=$newsedit->where("news_id=$u_e_id")->save();
            if($info)
            {
                $this->assign("jumpUrl","newslist");
                $this->success("信息修改成功!");
            }

        }
     }
     /**
    +----------------------------------------------------------
    *删除信息
    +----------------------------------------------------------
    */
      public function newsdel()
    {
        $newsdel=M("news");
        if(isset($_GET['d_id']))
        {
            $d_id=$_GET['d_id'];
            $del_result=$newsdel->where("news_id=$d_id")->delete();
            if($del_result)
            {
                $this->assign("jumpUrl","__URL__/newslist");
                $this->success("信息删除成功!");
            }
        }

     }

}
?>
